/*
 * Copyright © 2024-2025 Wenze Wei
 *
 * This file is part of StadionOS.
 *
 * This Source Code Form is subject to the terms of the GNU General Public License, v. 2.0.
 * You can obtain a copy of the GPL at
 * https://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 */

#include "../include/string.h"

/**
 * @brief Compare two memory blocks.
 *
 * @param str1 The first memory block.
 * @param str2 The second memory block.
 * @param n The number of bytes to compare.
 * @return An integer less than, equal to, or greater than zero if str1 is found to be less than, equal to, or greater than str2, respectively.
 */
int Smemcmp(const void *str1, const void *str2, size_t n) {
    const unsigned char *s1 = str1;  
    const unsigned char *s2 = str2;

    while (n--) {  
        if (*s1 != *s2) {  
            return *s1 - *s2;  
        }  
        s1++;  
        s2++;  
    }  
    return 0;  
}
